/*
    Bandleader
    Copyright (c) 2006 by Grant Yoshida

    Licensed under the GPL version 2 or later,
    please see COPYING for details.
*/

#include "OpenRow.h"
//
#include "ChordView.h"
#include "Document.h"
#include "InsertBarAfter.h"

OpenRow::OpenRow(ChordView *view, int index, QUndoCommand *parent) :
    QUndoCommand("Open Row", parent),
    m_view(view),
    m_document(),
    m_index(index)
{
    if (m_view)
        m_document = m_view->getDocument();
}

void OpenRow::undo()
{
    QUndoCommand::undo();

    if (m_view)
        m_view->setCursorPosition(m_index);
}

void OpenRow::redo()
{
    if (m_document) {
        int row = m_view->rowOfIndex(m_index) + 1;

        int indexOfNextRow = m_view->indexOfRow(row) - 1;

        int cellsPerRow = m_view->cellsPerRow();

        for (int i = 0; i < cellsPerRow; ++i) {
            new InsertBarAfter(m_view, indexOfNextRow, this);
        }
    }

    QUndoCommand::redo();
}
